package com.aletto.general_store.data;

import com.aletto.general_store.data.model.Response;
import com.aletto.general_store.data.model.SearchKeyword;

import java.util.ArrayList;
import java.util.List;

public class MapUtils {

    public static Response<List<String>> hot_search(Response<SearchKeyword> response){
        if (response != null) {
            List<String> keywords = new ArrayList<>();
            SearchKeyword data = response.getData();

            if (data != null) {
                data.getHotSearch().forEach(item -> keywords.add(item.getName()));
            }

            return new Response<>(keywords, response.getCode(), response.getMessage());
        }

        return new Response<>(new ArrayList<>(), 0, "map error");
    }

    public static Response<List<String>> search_prompt(Response<List<SearchKeyword.HotSearch>> response){
        if (response != null) {
            List<String> keywords = new ArrayList<>();

            List<SearchKeyword.HotSearch> data = response.getData();
            if (data != null) {
                data.forEach(item -> keywords.add(item.getName()));
            }

            return new Response<>(keywords, response.getCode(), response.getMessage());
        }

        return new Response<>(new ArrayList<>(), 0, "map error");
    }

}
